package com.clp.protocol.iec104.iec104.server.slave;

import com.clp.protocol.core.common.Checkable;
import com.clp.protocol.iec104.iec104.server.slavechannel.pipeline.state.data.TcDataReactor;
import com.clp.protocol.iec104.iec104.server.slavechannel.pipeline.state.data.TotalCall100DataReactor;
import com.clp.protocol.iec104.iec104.server.slavechannel.pipeline.state.data.TotalCall101DataReactor;
import com.clp.util.AssertUtil;
import lombok.Getter;

/**
 * 子站数据配置
 */
@Getter
public class SlaveDataConfig implements Checkable {
    private final TotalCall100DataReactor totalCall100DataReactor;
    private final TotalCall101DataReactor totalCall101DataReactor;
    private final TcDataReactor tcDataReactor;

    private SlaveDataConfig(Configurer cfgr) {
        this.totalCall100DataReactor = cfgr.totalCall100DataReactor;
        this.totalCall101DataReactor = cfgr.totalCall101DataReactor;
        this.tcDataReactor = cfgr.tcDataReactor;
    }

    public static Configurer configurer() {
        return new Configurer();
    }

    @Override
    public void check() throws Throwable {
        AssertUtil.notNull(totalCall100DataReactor, "totalCall100DataReactor");
        AssertUtil.notNull(totalCall101DataReactor, "totalCall101DataReactor");
        AssertUtil.notNull(tcDataReactor, "tcDataReactor");
    }

    public static class Configurer {
        private TotalCall100DataReactor totalCall100DataReactor;
        private TotalCall101DataReactor totalCall101DataReactor;
        private TcDataReactor tcDataReactor;

        public Configurer totalCall100DataReactor(TotalCall100DataReactor totalCall100DataReactor) {
            this.totalCall100DataReactor = totalCall100DataReactor;
            return this;
        }

        public Configurer totalCall101DataReactor(TotalCall101DataReactor totalCall101DataReactor) {
            this.totalCall101DataReactor = totalCall101DataReactor;
            return this;
        }

        public Configurer tcDataReactor(TcDataReactor tcDataReactor) {
            this.tcDataReactor = tcDataReactor;
            return this;
        }

        public SlaveDataConfig configOk() {
            return new SlaveDataConfig(this);
        }

    }
}
